package com.slz3.business.module.socialManagement.socSign.service;

import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Repositorys;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.steward.PageableSteward;
import com.slz3.business.module.socialManagement.socSign.domain.SocSign;
import com.slz3.business.module.socialManagement.socSign.domain.SocSignFactory;
import com.slz3.business.module.socialManagement.socSign.steward.SocSignSpecification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

import java.util.*;

@Slf4j
@Service
public class SocSignServiceImpl implements SocSignService {

    @Override
    public SocSign save(SocSign socSign) {
        return Repositorys.socSign.save(SocSignFactory.initBaseFields(socSign));
    }

    @Override
    public Page<SocSign> page(MultiValueMap<String, String> params) {
        Page<SocSign> socSignPage = Repositorys.socSign.findAll(
                SocSignSpecification.findJoin(params), PageableSteward.extract(params)
        );
        return socSignPage;
    }

    @Override
    public SocSign modify(SocSign socSignNew) {
        return Repositorys.socSign.saveAndFlush(SocSignFactory.initBaseFields(socSignNew));
    }

    @Override
    public Optional<SocSign> single(UUID uuid) {
        return Repositorys.socSign.findById(uuid);
    }

    @Override
    public List<SocSign> findAllByUuids(Iterable<UUID> uuids) {
        return Repositorys.socSign.findAllById(uuids);
    }

    @Override
    public List<SocSign> delete(List<SocSign> socSignList) {
        socSignList.stream().forEach(item -> {
            item.setValidFlag(ValidFlag.DEL);
            SocSignFactory.initBaseFields(item);
        });
        return Services.socSignTransactional.batchModify(socSignList);
    }

}
